<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js"></script>
</head>

<body>
    <button id="getBtn">Get</button>
    <button id="postBtn">Post</button>
    <button id="deleteBtn">Delete</button>
    <script>
        $(function () {
            $('#getBtn').on('click', function () {
                $.ajax({
                    type: 'GET',
                    url: 'http://127.0.0.1/api/get',
                    data: {
                        name: '张三',
                        age: 18,
                        desc: "法外狂徒"
                    },
                    success: function (res) {
                        console.log(res);
                    }
                })
            })
            $('#postBtn').on('click', function () {
                //解决跨域问题cors，jsonp（只能解决get）
                $.ajax({
                    type: 'POST',
                    url: 'http://127.0.0.1/api/post',
                    data: {
                        name: '水浒传',
                        author: '施耐庵',
                        desc: "法外狂徒"
                    },
                    success: function (res) {
                        console.log(res);
                    }
                })
            })
            $('#deleteBtn').on('click', function () {
                //解决跨域问题cors，jsonp（只能解决get）
                $.ajax({
                    type: 'DELETE',
                    url: 'http://127.0.0.1/api/delete',
                    success: function (res) {
                        console.log(res);
                    }
                })
            })
        })
    </script>
</body>

</html>